
var utils = require('../../utils/getTool');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    jobTitle:"巡检任务定制与分配",
    activeKey:0,
    sidebarIndex:0,
    hideSidebar:false,
    jobType:{name:'',value:0},
    bugLeve:{name:'',value:0 },
    bugType: { name: '', value: { configValueId: 0 } },
    inpCode: '',
    inpByLineCode: '',
    issuedByName: '',
    jobTypeList: [{ name: "待分配", value: 1 }, { name: "已分配", value: 2 }, { name: "执行中", value: 3 }, { name: "已完成", value: 4 }],
    bugLeveList: [{name:"查询全部",value:0},{ name: "一般", value: 1 }, { name: "紧急", value: 2 }, { name: "严重", value: 3 }],
    active: 0
  },
  onAddInsMain(){
    wx.navigateTo({
      url: "../inspectiontask/addInsMain/addInsMain"
    })
  },
  bugQue(){
    console.log(this.data)
    utils.req({
      url:getApp().appData.site+"/accp/psInspectiontaskDetail/getBugInfo",
      data:{
        inspectionTaskCode:this.data.inpCode,
        lineCode:this.data.inpByLineCode,
        bugType: this.data.bugType.value.configValueId,
        bugLevel:this.data.bugLeve.value
      },
      success:res=>{
        if (res.statusCode==200){
          getApp().appData.inspectionList = res.data //将这个值设置为全局变量
          wx.navigateTo({
            url: "../inspectiontask/quexianQue/quexianQue"
          })
        }
      }
    })
  },
  quehuizhi(){
    var dat = {
      inspectionTaskCode: this.data.inpCode,
      lineCode: this.data.inpByLineCode,
      issuedByName: this.data.issuedByName,
      taskStatusName: this.data.jobType.name
    }
    this.que(dat,"../inspectiontask/huizhi/huizhi")
  },
  onSidebar(e){ //侧边栏你选中的索引
    if (e.detail==0){
      this.setData({
        jobTitle:"巡检任务定制与分配"
      })
    } else if (e.detail == 1){
      this.setData({
        jobTitle: "巡检任务执行与回执"
      })
    } else {
      this.setData({
        jobTitle: "缺陷查询"
      })
    }
    this.setData({
      sidebarIndex: e.detail,
    })    
  },
  onClose() {
    this.setData({ hideSidebar: false });
  },
  showSidebar(){
    if (!this.data.hideSidebar){
      this.setData({
        hideSidebar: true
      })
    }else{
      this.setData({
        hideSidebar: false
      })
    }    
  },
  quelineInfo(){
    var dat = {
      inspectionTaskCode: this.data.inpCode,
      lineCode: this.data.inpByLineCode,
      issuedByName: this.data.issuedByName,
      taskStatusName: this.data.jobType.name
    }
    this.que(dat,'../inspectiontask/cx/cx')
  },
  que(dat,locat){ //查询的方法 
    utils.req({
      url:getApp().appData.site+"/accp/psInspectiontaskMain/queInspection",
      data:{
        psInspectiontaskMain: dat
      },
      success:(res)=>{
        console.log(res)
        if(res.data){
          var myFor = [] ;
          for(var i in res.data){
            myFor.push(res.data[i])
            myFor[i].issuedTime = utils.dateConvert(res.data[i].issuedTime);
            myFor[i].finishTime =  utils.dateConvert(res.data[i].finishTime);
            myFor[i].creationTime =utils.dateConvert(res.data[i].creationTime);// 你要哪个日期我就格式换后并且一起传递过去
          }
          console.log(myFor)
          getApp().appData.inspectionList = myFor //将这个值设置为全局变量
          wx.navigateTo({
            url: locat
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo: wx.getStorageSync('userInfo')
    })
    utils.req({
      url: getApp().appData.site+"/accp/psInspectiontaskDetail/getBugTyle",
      data: {},
      success: res => {
        var myFor = [];
        for (var i in res.data) {
          myFor.push({
            name: res.data[i].configValueName,
            value: res.data[i]
          })
        }
        this.setData({
          bugTypeList: myFor
        })
      }
    })
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  issuedByName(e) {
    this.setData({
      issuedByName: e.detail
    })
  },
  inpByLineCode(e) {
    this.setData({
      inpByLineCode: e.detail
    })
  },
  inpCode(e) {
    this.setData({
      inpCode: e.detail
    })
  },
  seleType(e) {
    this.setData({
      jobType:{name:e.detail.name,value:e.detail.value},
      showType: false
    })
  },
  onshowType() {
    this.setData({
      showType: true
    })
  },
  hideType() {
    this.setData({
      showType: false
    })
  },
  onshowBugType(){
    this.setData({
      showBugType:true
    })
  },
  selectBugType(e){
    this.setData({
      bugType: { name: e.detail.name, value: e.detail.value},
      showBugType: false
    })
  },
  hidelBugType(){
    this.setData({
      showBugType: false
    })
  },
  onshowBugLeve(){
    this.setData({
      showBugLeve:true
    })
  },
  seleBugLeve(e) {
    this.setData({
      bugLeve: { name: e.detail.name, value: e.detail.value },
      showBugLeve: false
    })
  },
  hideBugLeve(){
    this.setData({
      showBugLeve: false
    })
  }
})